﻿using System.Web.Mvc;
using Uber.Core.Model;
using Uber.Core.Service;

namespace Uber.WebUI.Controllers
{
    [Authorize(Roles = The.Admin)]
    public class BanIpsController : Controller
    {
        private readonly IBannedIps bannedIps;

        public BanIpsController(IBannedIps bannedIps)
        {
            this.bannedIps = bannedIps;
        }

        public ActionResult Index()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Ban(string ip)
        {
            bannedIps.Ban(ip);
            Caching.RegHost(ip, false);
            return RedirectToAction("Index");
        }

        [HttpPost]
        public ActionResult UnBan(string ip)
        {
            bannedIps.UnBan(ip);
            Caching.RegHost(ip, true);
            return RedirectToAction("Index");
        }

    }
}